cmake_minimum_required(VERSION 3.15)
#cmake_policy(SET CMP0144 OLD)
#cmake_policy(SET CMP0167 OLD)
# 项目名称、版本和默认使用C++语言
project(libirc)

# 设置C++标准及相关属性
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
if(WIN32)
    add_definitions(-D_WIN32_WINNT=0x0A00)
endif()

# 设置各类项目路径
set(CMAKE_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libs")
set(RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libs")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/libs")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Release")

# ========================================boost begin===============
# 设置Boost库的根目录（应指向 Boost 的安装根目录）
# 直接调用build.bat是不会出现没有BOOST_ROOT的情况的
# 这段处理只是满足正确配置config.ini后，编辑器第一次打开，CMAKE工具自动执行不报错
if (NOT DEFINED BOOST_ROOT)
    set(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/boost")
    file(READ "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" INI_CONTENT)
    string(REPLACE "\n" ";" INI_LINES "${INI_CONTENT}")
    
    foreach(line IN LISTS INI_LINES)
        string(STRIP "${line}" stripped_line)
        if(NOT stripped_line OR stripped_line MATCHES "^[;#]")
            continue()
        endif()
        
        if(stripped_line MATCHES "^([^=]+)=(.*)$")
            set(key "${CMAKE_MATCH_1}")
            set(value "${CMAKE_MATCH_2}")
            string(STRIP "${key}" key)
            string(REGEX REPLACE "^\"(.*)\"$" "\\1" value "${value}")
            string(STRIP "${value}" value)
            if(key STREQUAL "OPENSSL_ROOT_DIR")
                set(OPENSSL_ROOT_DIR "${value}")
            endif()
            if(key STREQUAL "OPENSSL_INC")
                set(OPENSSL_INC_DIR "${value}")
            endif()
            if(key STREQUAL "OPENSSL_LIB")
                set(OPENSSL_LIB_DIR "${value}")
            endif()
        endif()
    endforeach()
endif()
set(BOOST_NO_SYSTEM_PATHS ON)
set(BOOST_INC_DIR ${BOOST_ROOT})
set(BOOST_LIB_DIR ${BOOST_ROOT}\\lib)

# 查找Boost库，指定需要的组件
find_package(Boost REQUIRED)
find_package(Openssl REQUIRED COMPONENTS crypto ssl)

# 输出 Boost 的相关信息
message("Boost version: ${Boost_VERSION}")
message("OPENSSL_ROOT_DIR: ${OPENSSL_ROOT_DIR}")
message("BOOST_INC_DIR: ${BOOST_INC_DIR}")
message("BOOST_LIB_DIR: ${BOOST_LIB_DIR}")
message("OPENSSL_INC_DIR: ${OPENSSL_INC_DIR}")
message("OPENSSL_LIB_DIR: ${OPENSSL_LIB_DIR}") 
# 包含头文件目录
include_directories(${BOOST_INC_DIR} ${OPENSSL_INC_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/AuthClient)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Image)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Message)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Public)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/WebSocketClient)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Settings)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/VirtualMedia)

# 链接库目录
link_directories(${BOOST_LIB_DIR} ${OPENSSL_LIB_DIR})

# 添加api代码路径
add_subdirectory(src)

# 添加测试代码路径
add_subdirectory(example)